package com.jueling.culture.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author by linp
 * @date 2019/10/15
 */
public class CollectionUtil {
    /**
     * 判断为空集合
     * @param collection
     * @return
     */
    public static Boolean isEmptyCollection(Collection<?> collection) {
        if (collection == null) {
            return true;
        }
        return collection.isEmpty();
    }
    /**
     * 判断不为空集合
     * @param collection
     * @return
     */
    public static Boolean isNotEmptyCollection(Collection<?> collection) {
        return !isEmptyCollection(collection);
    }


    /**
     * 移除重复数据
     * @param list1 主数据
     * @param list2 切割数据
     * @return
     * @throws Exception
     */
    public static List<String> removeRepeatFactor(List<String> list1 , List<String> list2){
        if(list1 != null && list2 != null) {
            if (list1.size() != 0 && list2.size() != 0) {
                Collection A = new ArrayList(list1);
                Collection B = new ArrayList(list2);
                A.retainAll(B);
                if (A.size() != 0) {
                    B.removeAll(A);
                }
                return (List<String>) B;
            }
        }
        return list2;
    }


    public static void main(String[] args) throws Exception {
        List<String> one = new ArrayList<>();
        List<String> ones = new ArrayList<>();

        one.add("app_tengxxw1");
        one.add("app_tengxxw2");
        one.add("app_tengxxw3");
        one.add("app_tengxxw4");
        one.add("app_tengxxw5");


        ones.add("app_tengxxws");
        ones.add("app_tengxxws1");
        ones.add("app_tengxxw1");
        ones.add("app_tengxxw2");

        System.out.println(removeRepeatFactor(one,ones));
    }
}
